'use strict';

const db = uniCloud.database();

async function login(event){
	event.zt = 0;
	if (!event.name || !event.pass) {
		return event;
	}
	
	let res = await db.collection('user_account').where({
		"account": event.name
	}).get()
	
	if(res.affectedDocs>0){
		if(res.data[0].password == event.pass){
			event = {
				"zt":1
			}
		}
	}
	return event;
}

exports.main = async (event, context) => {
	//event为客户端上传的参数
	console.log('event : ', event)
	if (!event.type) {
		return event;
	}
	
	switch(event.type){
		case "login":
			return login(event);
		break;
		
	}
	
	//返回数据给客户端
	return event
};
